home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_01 / allison / bits.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-12-07  |  1.6 KB  |  63 lines

  1. template<unsigned long N>
  2. class bits
  3. {
  4. // Friends:
  5.     // Global I/O funtions
  6.     friend ostream& operator<<(ostream&, const bits<N>&);
  7.     friend istream& operator>>(istream&, bits<N>&);
  8.  
  9.     // Global bitwise operators
  10.     friend bits<N> operator&(const bits<N>&, const bits<N>&);
  11.     friend bits<N> operator|(const bits<N>&, const bits<N>&);
  12.     friend bits<N> operator^(const bits<N>&, const bits<N>&);
  13.  
  14. public:
  15.     // Constructors
  16.     bits();
  17.     bits(unsigned long n);
  18.     bits(const bits<N>& b);
  19.     bits(const string& s);
  20.  
  21.     // Conversions
  22.     unsigned short to_ushort() const;
  23.     unsigned long to_ulong() const;
  24.     string to_string() const;
  25.  
  26.     // Assignment
  27.     bits<N>& operator=(const bits<N>& rhs);
  28.  
  29.     // Equality
  30.     int operator==(const bits<N>& rhs) const;
  31.     int operator!=(const bits<N>& rhs) const;
  32.  
  33.     // Basic bit operations
  34.     bits<N>& set(size_t pos, int val = 1);
  35.     bits<N>& set();
  36.     bits<N>& reset(size_t pos);
  37.     bits<N>& reset();
  38.     bits<N>& toggle(size_t pos);
  39.     bits<N>& toggle();
  40.     bits<N> operator~() const;
  41.     int test(size_t n) const;
  42.     int any() const;
  43.     int none() const;
  44.  
  45.     // Bit-wise operators
  46.     bits<N>& operator&=(const bits<N>& rhs);
  47.     bits<N>& operator|=(const bits<N>& rhs);
  48.     bits<N>& operator^=(const bits<N>& rhs);
  49.  
  50.     // Shift operators
  51.     bits<N>& operator<<=(size_t n);
  52.     bits<N>& operator>>=(size_t n);
  53.     bits<N> operator<<(size_t n) const;
  54.     bits<N> operator>>(size_t n) const;
  55.  
  56.     size_t count() const;
  57.  
  58.     size_t length() const;
  59. };
  60.  
  61. // End of File
  62.  
  63.